<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        * {
            list-style: none;
            margin: 0;
            padding: 0;
        }

        #shop-car li {
            border: 1px dotted red;
            margin: 20px 0;
            padding: 20px;
        }

        .container {
            width: 400px;
            padding: 20px;
        }
    </style>
</head>

<body>

    <div class="container">
        <input type="checkbox" id="isAllCheck" /> 全选
        <ul id="shop-car">
            <!-- 
            <li>
                <input type="checkbox" />
                <div>商品名称:</div>
                <img src="https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg" alt="">
                <div>商品价格:50</div>
                <div>购买数量:30</div>
                <div>商品规格: 黑</div>
                <div>是否选中：选中吧OR不选中</div>
            </li>
            <li>
                <input type="checkbox" />
                <div>商品名称:</div>
                <img src="https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg" alt="">
                <div>商品价格:50</div>
                <div>购买数量:30</div>
                <div>商品规格: 黑</div>
                <div>是否选中：选中吧OR不选中</div>
            </li> -->
        </ul>
        <p id="totalnum">总数量：xxx</p>
        <p id="totalprice">总价格：xxx</p>
    </div>


    <script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.js"></script>
    <script>
        //            作业1：有以下购物车数据，使用这些数据渲染页面，根据每一个商品中的选中状态决定全选状态、总数量和总价格



        let products = [
            {
                goods_name: '小米10-1',
                goods_img: 'https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg',
                goods_price: '500',
                goods_attr: '砂石黑4GB+64GB',
                goods_num: 10,
                goods_is_checked: true
            },
            {
                goods_name: '小米10-2',
                goods_img: 'https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg',
                goods_price: '510',
                goods_attr: '砂石黑4GB+64GB',
                goods_num: 50,
                goods_is_checked: true
            }
        ]
        console.log($("#shop-car"));
        let price = [];
        let num = [];
        for (let i = 0; i < products.length; i++) {
            products[i].goods_is_checked = products[i].goods_is_checked == false ? "未选中" : "选中";
            $("#shop-car")[0].innerHTML += `
        <li>
                <input type="checkbox" />
                <div>${products[i].goods_name}</div>
                <img src="${products[i].goods_img}" alt="">
                <div>商品价格:${products[i].goods_num}</div>
                <div>购买数量:${products[i].goods_price}</div>
                <div>商品规格: ${products[i].goods_attr}</div>
                <div>是否选中：${products[i].goods_is_checked}</div>
            </li>
            `
            if (products[i].goods_is_checked == "选中") {
                price[i] = Number(products[i].goods_price);
                num[i] = Number(products[i].goods_num);
                $("li>input:checkbox").attr("checked", "check");
            }
        }
        if ($("li>input[checked*='check']").length == $("li>input:checkbox").length) {
            $("#isAllCheck").attr("checked", "check")
        }
        let a = 0, b = 0;
        console.log(price);
        for (let k = 0; k < price.length; k++) {
            a += price[k];
            b += num[k];

        }
        $("#totalnum")[0].innerHTML = `总数量:${b}`
        $("#totalprice")[0].innerHTML = `总价格:${a}`
        // <p id="totalnum">总数量：xxx</p>
        // <p id="totalprice">总价格：xxx</p>



        // 第二题

    </script>
</body>

</html>